<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>栏目管理<small></small></h5>
                </div>
                <div class="ibox-content">
                    <div class="">
                        <a href="/admin/category/create?cid=0" class="btn btn-primary ">添加</a>
                    </div>
                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>栏目路由规则</th>
                            <th>栏目名称</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($categorys as $category)
                            <tr class="gradeA">
                                <td>{{ $category['id'] }}</td>
                                <td>{{ $category['name'] }}</td>
                                <td>{{ $category['label'] }}</td>
                                <td class="center">
                                    <a href="/admin/category/create?cid={{ $category['id'] }}">添加</a>
                                    <a href="/admin/category/edit?catId={{ $category['id'] }}">|编辑</a>
                                    <a href="javascript:void(0);" class="delete-product" data-value="{{ $category['id'] }}" data-title="{{ $category['label'] }}">|删除</a>
                                </td>
                            </tr>
                            @foreach($category['childs'] as $child )
                                <tr class="gradeA">
                                    <td>{{ $child['id'] }}</td>
                                    <td>{{ $child['name'] }}</td>
                                    <td>&nbsp;|--{{ $child['label'] }}</td>
                                    <td class="center">
                                        <a href="/admin/category/edit?catId={{ $child['id'] }}">编辑</a>
                                        <a href="javascript:void(0);" class="delete-product" data-value="{{ $child['id'] }}" data-title="{{ $child['label'] }}">|删除</a>
                                    </td>
                                </tr>
                            @endforeach
                        @endforeach

                        </tbody>
                        <tfoot>
                            <tr>
                                <th>ID</th>
                                <th>栏目路由规则</th>
                                <th>栏目名称</th>
                                <th>操作</th>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>

</div>

<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>

<script src="/js/plugins/layer/layer.min.js"></script>


<!-- Page-Level Scripts -->
<script>
    $(document).ready(function () {

        $('.delete-product').click(function () {
            var docuElem=$(this);
            var catId=docuElem.data('value');
            var title=docuElem.data('title');
            if(window.confirm('你确定删除'+ title+ '？')){
                //继续执行
                $.ajaxSetup({
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                });
                $.ajax({
                    type:'post',
                    url:'/admin/category/delete',
                    dataType:'json',
                    data:{catId:catId},
                    success: function(data){
                        data=eval(data);
                        if(data.code==200){
                            layer.msg(data.message, {icon: 6});
                            docuElem.parents('.gradeA').remove();
                        }else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });


            }
        });
        //====
        $("select[name='pageSize']").change(function () {
            $('form').submit();
        });


    });

</script>

</body>

</html>
